import request from "../utils/request"



/**
 * 发送手机验证码
 */
export const sendSmsCodeApi = (phone) => {
	return request({
		method: "GET",
		url:'/portal/user/send_sms_code',
		data:{
			phone
		}
	})
}


/**
 * 手机验证码登录
 */
export const loginByCodeApi = ({phone,code}) =>{
	return request({
		method: 'post',
		url:'/portal/user/login/phone',
		data:{
			phone,code
		}
	})
}



/**
 * 获取用户数据
 */
export const getUserInfoApi = () => {
	return request({
		method:'get',
		url:'/portal/user/info',
		showLoading: false // 不显示加载动画
	})
}


/**
 * 修改信息接口
 */
export const modifyUserInfoApi = (data) => {
	return request({
		method: 'post',
		data: data,
		url:'/portal/user/modify'

	})
}

/**
 * 上传头像接口
 */
export const uploadAvatarApi = (formData) => {
	return request({
		method: 'post',
		data: formData,
		url:'/portal/user/upload/avatar',
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}

// 获取阿里云OSS直传签名
export const getAvatarUploadSignApi = () => {
  return request({
    url: '/portal/user/get_avatar_upload_sign',
    method: 'GET'
  })
}


// 更新头像
export const updateAvatarApi = (url) => {
  return request({
    url: `/portal/user/avatar_update?avatarUrl=${url}`,
    method: 'POST'
  })
}

/**
 * 获取当前用户的公司申请审核信息
 */
export const getCompanyReviewApi = () => {
  return request({
    method: 'get',
    url: '/portal/user/company/review/current'
  })
}

/**
 * 获取当前用户的HR申请信息
 */
export const getHrApplyApi = () => {
  return request({
    method: 'get',
    url: '/portal/user/hr/apply/current'
  })
}

/**
 * 获取申请HR所需文件的上传签名
 */
export const getHrApplyUploadSignApi = () => {
	return request({
		method: 'get',
		url: '/portal/user/get_user_hr_apply_sign'
	})
}

/**
 * 用户申请成为HR
 * @param {Object} data - 申请数据
 * @param {string} data.realName - 真实姓名
 * @param {string} data.phone - 联系电话
 * @param {string} data.authFileUrl - 授权书URL
 */
export const applyToBeHrApi = (data) => {
	return request({
		method: 'post',
		url: '/portal/user/hr_apply',
		data: data
	})
}


/**
 * 用户退出登录
 */
export const logoutApi = () => {
	return request({
		method: 'post',
		url: '/portal/user/logout'
	})
}



/**
 * 获取hr信息
 */
export const getHrInfoApi = () => {
	return request({
		method: 'get',
		url: '/portal/user/getHrUserInfo'
	})
}

/**
 * 根据hrId获取HR信息（供求职者查看）
 * @param {string} hrId - HR用户ID
 */
export const getHrInfoByIdApi = (hrId) => {
	return request({
		method: 'get',
		url: `/portal/user/getHrUserInfoByHrId?hrId=${hrId}`
	})
}

/**
 * 更新公司用户绑定信息
 */
export const updateCompanyUserBindInfoApi = (data) => {
	return request({
		method: 'post',
		url: '/portal/user/update_company_user_bind_info',
		data: data
	})
}

/**
 * 用户解除与公司的绑定
 * @returns 
 */

export const company_user_unbind = () => {
	return request({
		method: 'post',
		url: '/portal/user/user_company_unbind'
	})
}

/**
 * 获取附件简历上传签名
 * @param {string} fileExt - 文件扩展名
 */
export const getAttachmentUploadSignApi = (fileExt) => {
  return request({
    url: '/portal/user/get_attachment_upload_sign',
    method: 'POST',
    data: {
      fileExt: fileExt
    }
  })
}

/**
 * 添加附件简历
 * @param {Object} data - 附件数据
 * @param {string} data.fileName - 文件名
 * @param {number} data.fileSizeMb - 文件大小(MB)
 * @param {string} data.fileType - 文件类型
 * @param {string} data.fileUrl - 文件URL
 */
export const addAttachmentApi = (data) => {
  return request({
    method: 'post',
    url: '/portal/user/add_attachment',
    data: data
  })
}

/**
 * 获取我的附件列表
 */
export const getAttachmentsApi = () => {
  return request({
    method: 'get',
    url: '/portal/user/get_attachments'
  })
}

/**
 * 删除附件
 * @param {string} attachmentId - 附件ID
 */
export const deleteAttachmentApi = (attachmentId) => {
  return request({
    method: 'post',
    url: `/portal/user/delete_attachment?attachmentId=${attachmentId}`
  })
}